<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/header.php");
?>

<section>
<hgroup>
<h1>Screening</h1>
</hgroup>
<?php

    $query1="SELECT screeningroom.Id, screeningroom.RoomTypeId, roomtype.Name FROM screeningroom, roomtype where roomtype.Id=screeningroom.RoomTypeId and screeningroom.ScreeningVersionId='" .$_GET["id"]."'";
    $result1 = mysql_query($query1) or die ("FOUT1: " . mysql_error());

    // gegevens ophalen en toekennen aan tijdelijke variabelen
    while ($rij1 = mysql_fetch_array($result1)){
            $Id = $rij1['Id']; 
            echo "<h2>".$rij1['Name']."<a href=\"probleemtoevoegen.php?screenid=".$_GET["id"]."&roomid=".$rij1['RoomTypeId']."\" ><img src=\"../../images/add.png\" alt=\"add\" ></a></h2>";
            
            $query2="SELECT screeningitem.Id, roomitem.Name, screeningitem.Comment FROM screeningitem, roomitem where roomitem.Id=screeningitem.RoomItemId and screeningitem.ScreeningRoomId='" .$Id."'";
            $result2 = mysql_query($query2) or die ("FOUT1: " . mysql_error());

            echo "<ul>";
            // gegevens ophalen en toekennen aan tijdelijke variabelen
            while ($rij2 = mysql_fetch_array($result2)){
                    $ScreeningItemId = $rij2['Id']; 
                    echo "<li>".$rij2['Name']."</li>";
                    
                    echo "<ul>";
                    $query3="SELECT itemproblem.Id, itemproblem.Name, screeningproblem.ScreeningItemId, screeningproblem.ItemProblemId, screeningproblem.Value FROM screeningproblem, itemproblem where itemproblem.Id=screeningproblem.ItemProblemId and screeningproblem.ScreeningItemId='" .$ScreeningItemId."'";
                    $result3 = mysql_query($query3) or die ("FOUT1: " . mysql_error());
                    while ($rij3 = mysql_fetch_array($result3)){
                        $ItemId = $rij3['Id'];
                        
                        
                        echo "<li>";
                        echo $rij3['Name'];
                        $query5 = "SELECT * FROM screeningproblem WHERE ScreeningItemId=".$rij3['ScreeningItemId']." AND ItemProblemId=".$rij3['ItemProblemId']."";
                        $result5 = mysql_query($query5) or die (mysql_error());
                        while ($row5 = mysql_fetch_array($result5))
                        {
                            echo "<a href=\"probleemverwijderen.php?screeningid=".$_GET['id']."&screeningproblemid=".$row5['Id']."\" ><img src=\"../../images/delete.png\" alt=\"delete\" ></a>";
                        }
                        
                        echo "<ul>";
                        

                        $query4="SELECT * from itemproblem where Id='" .$ItemId."'";
                        $result4 = mysql_query($query4) or die ("FOUT4: " . mysql_error());
                        while ($rij4 = mysql_fetch_array($result4)){
                            if ($rij4['HasValue'] == "T")
                            {
                                echo "<li>Value: ".$rij3['Value']."</li>";
                            }
                        }
                        
                        echo "</ul>";
                        echo "</li>";
                    }
                    
                    
                    echo "<li>Comment: ".$rij2['Comment']."<a href=\"probleemaanpassen.php?itemid=".$ScreeningItemId."&screeningid=".$_GET['id']."\" ><img src=\"../../images/edit.png\" alt=\"edit\" ></a></li>";
                    echo "</ul>";
            }
            
            echo "</ul>";
    }
?>
</section>

<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/footer.php");
?>